package com.zmht.beike.biz.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zmht.beike.biz.IAreaContentBiz;
import com.zmht.beike.core.BaseBizImpl;
import com.zmht.beike.po.TIareacontent;
import com.zmht.beike.po.TSociality;

public class IAreaContentBizImpl extends BaseBizImpl implements IAreaContentBiz {

	public boolean deleteAreaContent(Serializable id) {
		try{
			Object obj = this.getIareaContentDAO().findById(TIareacontent.class, id);
			if(null!=obj){
				this.getIareaContentDAO().deleteObj(obj);
			}
		}catch(Exception e){
			return false;
		}
		return true;
	}

	public TIareacontent findById(Serializable id) {
		
		return (TIareacontent)this.getIareaContentDAO().findById(TIareacontent.class, id);
	}

	public List getAreaContent(Integer teacherId, Integer areaId,
			int startIndex, int pageSize) {
		String hql = "from TIareacontent t where t.teacherId="+teacherId+" and t.iareaId=null and t.iareaType="+areaId+" order by t.id";
		return this.getIareaContentDAO().findByPage(hql, startIndex, pageSize);
	}

	public int getAreaContentTotal(Integer teacherId, Integer areaId) {
		String hql = "from TIareacontent t where t.teacherId="+teacherId+" and t.iareaId=null and t.iareaType="+areaId;
		return this.getIareaContentDAO().findByPageAmount(hql);
	}

	public boolean saveAreaContent(TIareacontent content) {
		try{
			this.getIareaContentDAO().saveObj(content);
		}catch(Exception e){
			return false;
		}
		return true;
	}

	public boolean updateAreaContent(TIareacontent content) {
		try{
			this.getIareaContentDAO().updateObj(content);
		}catch(Exception e){
			return false;
		}
		return true;
	}

	public static void main(String [] args){
		ApplicationContext cxt;
		cxt = new ClassPathXmlApplicationContext(new String[]{"spring/spring.xml","spring/spring_dao.xml","spring/spring_beike.xml"});
		IAreaContentBizImpl biz = (IAreaContentBizImpl)cxt.getBean("iareaContentBizTag");
		List list = biz.getAreaContent(3, 1, 0, 100);
		System.out.println(list.size());
	}

	public List getAreaContentEdit(Integer targetId, Integer teacherId,
			Integer month, Integer week, Integer iareaType, int startIndex,
			int pageSize) {
		String hql = "from TIareacontent t where t.iaimId="+targetId+" and t.teacherId="+teacherId+" and t.month="+month+" and t.week="+week+" and t.iareaType="+iareaType;
		return this.getIareaContentDAO().findByPage(hql, startIndex, pageSize);
	
	}

	public int getAreaContentEditTotal(Integer targetId, Integer teacherId,
			Integer month, Integer week, Integer iareaType) {
		String hql = "from TIareacontent t where t.iaimId="+targetId+" and t.teacherId="+teacherId+" and t.month="+month+" and t.week="+week+" and t.iareaType="+iareaType;
		
		return this.getIareaContentDAO().findByPageAmount(hql);
	}
}
